import {mapMutations} from 'vuex'
// 引入antv组件
import F2 from '@/uni_modules/lime-f2/components/l-f2/f2-all.min.js';
export default {
    ...mapMutations([
		'upProjectInfo'
    ]),
	onDayClick(data){
		this.curDate = data.date;
		uni.navigateTo({
			url: '/pages/index/detail?date='+this.curDate
		})
	},
	toSend(){
		this.$refs.sendPopup.open()
	},
	closeSendPopup(){
		this.$refs.sendPopup.close()
	},
	toDetail(){
		uni.navigateTo({
			url: '/pages/index/detail'
		})
	},
	//获取我的前十关注
	getUserFollowPage() {
		let that = this
		if (that.loading) {
			return false
		}
		let params = {};
		params.pageNo = that.page
		params.pageSize = that.list_rows
		that.loading = true
		that.$httpRequest.get({
			that: that,
			url: 'h5/getUserFollowPage',
			params: params,
			success: res => {
				that.loading = false
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					if (that.page === 1) {
						that.userList = res.data.rows
					} else {
						that.userList = that.userList.concat(res.data.rows)
					}
					that.page++
				} else {
					
				}
			}
		})
	},
	changeMonth(e){
		let that = this
		let params = {
			month: e
		}
		that.$httpRequest.get({
			that: that,
			url: 'h5/getUserCalendarInfo',
			params: params,
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.calendarList = res.data
				}
			
			}
		})
	},
	//获取指定用户指定月份日历信息
	getUserCalendarInfo(id){
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getUserCalendarInfo',
			params: {
				month:that.$utils.getNowYearMonth()
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.calendarList = res.data
				}
			
			}
		})
	},
	//获取指定用户的今指数统计数据
	getUserTodayIndex(id){
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getUserTodayIndex',
			params: {
			
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.userTodayIndex = res.data
				}
			
			}
		})
	},
	//获取今日今指数图表数据
	getTodayIndex(id){
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getTodayIndex',
			params: {
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.baseData = res.data
					// 班组考勤==========================================================================
					this.$refs.todayIndex.init(config => {
						config.padding = [ 'auto', 20, 'auto', 'auto']
						const chart = new F2.Chart(config);
						chart.source(that.baseData, {
							// value:{//y轴的数值间隔
							// 	tickCount:30
							// }
						});
						chart
							.interval()
						.position('date*pointTotal')
						.color('date*pointTotal', [ 'rgba(252, 67, 142, 1)', 'rgba(35, 193, 101, 1)','rgba(92, 159, 254, 1)','rgba(255, 150, 43, 1)' ])
						 .style('pointTotal', {
						     radius: function radius(val) {
						       return val > 0 ? [ 2, 2, 0, 0 ] : [ 0, 0, 2, 2 ];
						     }
						   })
						.adjust('stack');//不分组
						chart.axis('date', {
							label:{
								fill: '#666666',
								rotate: -Math.PI / 2,
								textAlign: 'end',
								textBaseline: 'middle'
							}
						});
						chart.legend(false);
						// 柱状图添加文本
						that.baseData.forEach(function(obj) {
						  chart.guide().text({
						    position: [ obj.date, obj.pointTotal ],
						    content: obj.pointTotal,
						    style: {
						      textAlign: 'center',
						      textBaseline: 'bottom'
						    },
						    offsetY: 0
						  });
						});
						chart.render();
						// 需要把 chart 返回
						return chart;
					})
				}
			
			}
		})
	},
	handlerUpload(){
		let that = this;
		//上传照片
		that.$httpRequest.handlerUploadPic(res => {
			if (res.code === that.$httpConfig.SUCCESS_CODE) {
				// console.log(res,"完成上传")
				that.wordList.push(res.data)
				
				
			}
		});
	},
	toOtherTodayData(id){
		uni.navigateTo({
			url: '/pages/index/todayData?id='+id
		})
	},
	toNotice(){
		uni.navigateTo({
			url: '/pages/my/notice'
		})
	},
	_previewImage(image) {
		var imgArr = [];
		imgArr.push(image);
		//预览图片
		uni.previewImage({
			urls: imgArr,
			current: imgArr[0]
		});
	},
	toScreen(){
		
		
		// //获取网页中的canvas对象  
		let mycans= document.getElementsByTagName("canvas")[0];   
		console.log(mycans)
		// // //调用convertCanvasToImage函数将canvas转化为img形式   
		let img= this.convertCanvasToImage(mycans);  
		console.log(img)
		// //将img插入容器 
		// document.getElementById('screen-box').append(img);
	},
	//从 canvas 提取图片 image  
	convertCanvasToImage(canvas) {  
	    //新Image对象，可以理解为DOM  
	    var image = new Image();  
	    // canvas.toDataURL 返回的是一串Base64编码的URL
	    // 指定格式 PNG  
	    image.src = canvas.toDataURL("image/png");  
	    return image;  
	}
}